package Application.Controller;

import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Slider;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import Application.Tool.*;
import Application.File.FileAdd;
import javafx.scene.image.ImageView;
import java.io.File;
import Application.LayerImage.LayerImage;
import org.w3c.dom.Text;

public class TexturePenSettingsController {
    @FXML Slider sizeSetting;
    @FXML ComboBox<String> maskSetting;
    @FXML TextField originXSetting, originYSetting;
    @FXML TextField scaleSetting;
    @FXML Label lblFileName;
    @FXML ImageView texturePreview;

    @FXML public void onSizeChanged() {
        int size = (int)sizeSetting.getValue();
        TexturePen.getInstance().setSize(size);
    }

    @FXML public void onMaskChanged() {
        String maskName = maskSetting.getValue();

        TexturePen.getInstance().setMask(maskName);
    }

    @FXML public void onScaleChanged() {
        double scale = Double.parseDouble(scaleSetting.getText());
        TexturePen.getInstance().setScale(scale);
    }

    @FXML public void onBtnBrowseTextureClicked() {
        File file = FileAdd.fileChoose(null);
        LayerImage img = FileAdd.getLayerImageFromFile(file);

        lblFileName.setText(file.getAbsolutePath());
        texturePreview.setImage(img.getWritableImage());

        TexturePen.getInstance().setTexture(img);
    }

    @FXML public void onOriginChanged() {
        int ox = Integer.parseInt(originXSetting.getText());
        int oy = Integer.parseInt(originYSetting.getText());

        TexturePen.getInstance().setOrigin(ox, oy);
    }

    public ComboBox<String> getCombo() {
        return maskSetting;
    }

//    public TextField getXXX() {
//        return scaleSetting;
//    }
}
